(function (vc) {
    vc.extends({
        propTypes: {
            emitChooseHousekeepingResource: vc.propTypes.string,
            emitLoadData: vc.propTypes.string
        },
        data: {
            chooseHousekeepingResourceInfo: {
                housekeepingResources: [],
                _currentHousekeepingResourceName: '',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('chooseHousekeepingResource', 'openChooseHousekeepingResourceModel', function (_param) {
                $('#chooseHousekeepingResourceModel').modal('show');
                $that._refreshChooseHousekeepingResourceInfo();
                $that._loadAllHousekeepingResourceInfo(1, 10, '');
            });
        },
        methods: {
            _loadAllHousekeepingResourceInfo: function (_page, _row, _name) {
                var param = {
                    params: {
                        page: _page,
                        row: _row,
                        communityId: vc.getCurrentCommunity().communityId,
                        name: _name
                    }
                };

                //发送get请求
                vc.http.apiGet('housekeepingResource.listHousekeepingResources',
                    param,
                    function (json) {
                        var _housekeepingResourceInfo = JSON.parse(json);
                        $that.chooseHousekeepingResourceInfo.housekeepingResources = _housekeepingResourceInfo.housekeepingResources;
                    }, function () {
                        console.log('请求失败处理');
                    }
                );
            },
            chooseHousekeepingResource: function (_housekeepingResource) {
                if (_housekeepingResource.hasOwnProperty('name')) {
                    _housekeepingResource.housekeepingResourceName = _housekeepingResource.name;
                }
                vc.emit($props.emitChooseHousekeepingResource, 'chooseHousekeepingResource', _housekeepingResource);
                vc.emit($props.emitLoadData, 'listHousekeepingResourceData', {
                    housekeepingResourceId: _housekeepingResource.housekeepingResourceId
                });
                $('#chooseHousekeepingResourceModel').modal('hide');
            },
            queryHousekeepingResources: function () {
                $that._loadAllHousekeepingResourceInfo(1, 10, $that.chooseHousekeepingResourceInfo._currentHousekeepingResourceName);
            },
            _refreshChooseHousekeepingResourceInfo: function () {
                $that.chooseHousekeepingResourceInfo._currentHousekeepingResourceName = "";
            }
        }

    });
})(window.vc);
